home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / UNIX / C / C-STYLE / STYLE_ME.AWK < prev    next >
Text File  |  1992-11-23  |  876b  |  35 lines

  1. # Produce  "style" metrics for a C program
  2.  
  3. # Compute number of blank lines
  4.         { if (NF==0) { blank++; next }}
  5.  
  6. # Compute number of nunblank characters and embedded spaces
  7.         { nbchars = 0
  8.           for ( i = NF; i > 0; i-- ) nbchars += length($i)
  9.           nonblank += nbchars
  10.           start = index ($0, $1)
  11.           embedded += length - nbchars - ( start - 1) }
  12.     
  13. # Compute amount of indentation
  14. /^[ ]/        { indented += index($0,$1) -1 }
  15.  
  16. # Compute total number of characters
  17.         { chars += length }
  18.  
  19. # Compute number of modules
  20. /^[a-z_][a-z_0-9]*[ a-z_0-9]*\(.*\)/    { module++ }
  21.  
  22. # Compute number of goto's
  23. /^goto[ ]+|[ ]+goto[ ]+/        { jumps++ }
  24.  
  25. # Report results
  26. END    { print "NR " (NR+0)
  27.       print "LC " (NR-blank)
  28.       print "NB " (nonblank+0)
  29.       print "IN " (indented+0)
  30.       print "TC " (chars+0)
  31.       print "BL " (blank+0)
  32.       print "IM " (embedded+0)
  33.       print "MO " (module+0)
  34.       print "JU " (jumps+0) }
  35.